#include "smallwidget.h"
#include "sqlcontroller.h"
#include "userhome.h"

#include <QHBoxLayout>
#include <QPushButton>
#include <QDebug>

Smallwidget::Smallwidget( QWidget *parent)
    : QDialog(parent)
{
    this->setWindowTitle("更改弹窗");
    this->resize(300,200);
    spin = new QSpinBox(this);
    slider = new QSlider(Qt::Horizontal, this);

    QHBoxLayout *layout = new QHBoxLayout;//添加水平布局控件
    layout->addWidget(spin);
    layout->addWidget(slider);
    setLayout(layout);


    QPushButton *btn_ok = new QPushButton("确定",this);
    QPushButton *btn_cancel = new QPushButton("取消",this);
//    QHBoxLayout *layout2 = new QHBoxLayout;
//    layout2->addWidget(btn_ok);
//    layout2->addWidget(btn_cancel);
//    setLayout(layout2);
    btn_ok->move(20,150);
    btn_cancel->move(btn_ok->x()+btn_ok->width()+40,150);

     this->setWindowModality(Qt::WindowModality::ApplicationModal);//将窗口设置为模态


    //连接（两个控件间的连接）
    connect(spin,static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
            slider,&QSlider::setValue);
    connect(slider,&QSlider::valueChanged,spin,&QSpinBox::setValue);


    //确认与取消

    connect(btn_ok,&QPushButton::clicked,this,[=]()
    {
        SqlController::getSqlController()->setProdectNum(slider->value());
        //发送信号
        emit begin();
           //delete this;
    });



    connect(btn_cancel,&QPushButton::clicked,this,[=]()
    {
//        delete  this;
        this->close();
    });
}

void Smallwidget::reset()
{
    slider->setValue(0);
}

